package cn.explink.eap.core.metadata.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.explink.eap.core.common.model.json.DataGrid;
import cn.explink.eap.core.metadata.domain.DataType;
import cn.explink.eap.core.metadata.domain.Metadata;
import cn.explink.eap.core.metadata.service.MetadataService;
import cn.explink.eap.tag.core.easyui.TagUtil;

@Controller
@RequestMapping("/metadataController")
public class MetadataController {

	@Autowired
	private MetadataService metadataService = null;

	@RequestMapping(params = "list")
	public ModelAndView list() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("jeecg/metadata/metadata");

		return mav;
	}

	@RequestMapping(params = "datagrid")
	public void datagrid(Metadata md, DataGrid dataGrid, HttpServletResponse response) {
		this.getMetadataService().fillMetadata(dataGrid);
		TagUtil.datagrid(response, dataGrid);
	}

	@RequestMapping(params = "addOrEdit")
	public ModelAndView addOrEdit() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("jeecg/metadata/metadata-add");

		return mav;
	}

	@RequestMapping(params = "delete")
	public void delete() {

	}

	@RequestMapping(params = "getAllMetadata")
	@ResponseBody
	public List<Metadata> getAllMetadata() {
		return this.getMetadataService().getAllMetadata();
	}

	@RequestMapping(params = "getAllDataType")
	@ResponseBody
	public List<DataType> getAllDataType() {
		return this.getMetadataService().getAllDataType();
	}

	private MetadataService getMetadataService() {
		return this.metadataService;
	}

}
